﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using System.Web.Security;
using TTJ.DataModel;
using TTJ.Service.Pixabay;
using TTJ.Service.Unsplash;
using TTJ.WebView.Unsplash.DataStruct;

namespace TTJ.WebView.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Title = "TuiTuJun";
            return View();
        }

        public ActionResult GetImageListFromUnsplash()
        {
            string perpage = ConfigurationManager.AppSettings["PerPage"];
            int perPage = 10;
            if (!int.TryParse(perpage, out perPage)) perPage = 10;
            string keyword = Request["keyWord"];

            UnsplashHelper helper = new UnsplashHelper(perPage);
            TagImageList result = helper.GetImageList(keyword);
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        public ActionResult GetImageListFromPixabay()
        {
            string perpage = ConfigurationManager.AppSettings["PerPage"];
            int perPage = 10;
            if (!int.TryParse(perpage, out perPage)) perPage = 10;
            string keyword = Request["keyWord"];

            PixabayHelper helper = new PixabayHelper(perPage);
            TagImageList result = helper.GetImageList(keyword);
            return Json(result, JsonRequestBehavior.AllowGet);
        }
    }
}